<template>
  <elm-page-tb style="width: calc(100% - 1px);height: calc(100% - 1px)" :splite="false" :splite-show="false">
        <template #top>
          <el-input placeholder="请查询输入内容" prefix-icon='el-icon-search' size="mini" style="width: 250px;" v-model="postData.name" clearable></el-input>
            <right>
              <el-button-group>
                <el-button icon="el-icon-search" size="mini" @click="treebinding()">查询</el-button>
                <elm-open-button url="plan_task_edit" icon="el-icon-edit" title="新增" width="700" height="450" :data="{pid: '0',plan_code:postData.plan_code}">新增</elm-open-button>
                <elm-open-button url="plan_task_craft" icon="el-icon-edit" title="按工序添加" width="70%" height="70%" :data="{plan_code:postData.plan_code}">按工序添加</elm-open-button>
              </el-button-group>
            </right>
        </template>
        <elm-table-tree url="/business/plm/plan/task/GetTree" :post-data="postData" :page-size="50" :default-expand-all="true" height="100%">
            <el-table-column type="index" label="序号" width="60px" align="center"></el-table-column>
            <el-table-column prop="name" label="工作名称" header-align="center"></el-table-column>
            <el-table-column prop="jh_start_time" :formatter="formatDateTime" label="计划开始时间" align="center" width="160"></el-table-column>
            <el-table-column prop="jh_end_time" :formatter="formatDateTime" label="计划结束时间" align="center" width="160"></el-table-column>
            <el-table-column prop="priority" label="优先级" align="center" width="70"></el-table-column>
            <el-table-column prop="status" label="状态" align="center" width="70"></el-table-column>
            <el-table-column prop="assignee_id" label="负责人" align="center" width="100">
              <template v-slot="scope">
                {{ eiList.find(item => item.key === scope.row.assignee_id)?.value || '未分配' }}
              </template>
            </el-table-column>
            <el-table-column prop="sort" label="顺序" width="50px" align="center"></el-table-column>
            <el-table-column fixed="right" label="操作" width="160px" align="center">
                <template v-slot="scope">
                    <elm-open-button url="plan_task_edit" :title="'编辑[' + scope.row.name + ']'" width="700" height="450" :data="{ model: scope.row ,plan_code:postData.plan_code}" type="text">编辑</elm-open-button>
                    <elm-open-button url="plan_task_edit" :title="'新增[' + scope.row.name + ']的下级'"  width="700" height="450"
                                     :data="{  pid: scope.row.id ,plan_code:postData.plan_code}" type="text">新增下级</elm-open-button>
                    <el-button type="text" size="mini" @click="deleteData(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </elm-table-tree>
    </elm-page-tb>
</template>

<script>
export default {
    extends: elmVueBase,
    data() {
        return {
            postData: {name: null,plan_code:elm.dialog.request.plan_code, },
            eiList:[]
        }
    },
    async created() {
      this.eiList = await this.get_ei();
    },
    methods: {
        async deleteData(data) {
            await this.delete('/business/plm/plan/task/Delete', { id: data.id });
            let res=await elm.post("/business/plm/plan/stage/GetData",{plan_id:data.id});
            if(res.length>0)
              await elm.post("/business/plm/plan/stage/Delete",res[0]);
            this.treebinding();
        },
      async get_ei(){
        var res = await elm.post('/business/my/business/GetEi');
        //console.log(res);
        if(res.length>0)
          return res;
        else
          return [];
      },
    }
}
</script>

<style scoped>
</style>